var e = getApp();

Page({
    data: function(e, a, t) {
        return a in e ? Object.defineProperty(e, a, {
            value: t,
            enumerable: !0,
            configurable: !0,
            writable: !0
        }) : e[a] = t, e;
    }({
        id: "",
        baseUrl: e.globalData.baseUrl,
        order: {},
        server: {},
        orderServerList: [],
        store: {}
    }, "baseUrl", e.globalData.baseUrl),
    onLoad: function(a) {
        this.setData({
            serDetail: e.globalData.serDetail,
            yuyueTime: e.globalData.yuyueTime
        });
    },
    getinitData: function(e) {
        var a = this;
        wx.request({
            url: e,
            data: {
                orderId: a.data.id
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(e) {
                var t = JSON.parse(e.data);
                0 != t.code && wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                }), a.setData({
                    order: t.order,
                    server: t.server,
                    orderServerList: t.orderServerList,
                    store: t.store
                });
            }
        });
    },
    toPay: function(a) {
        var t = this, r = wx.getStorageSync("userId");
        if (r && r.length > 0 && (e.globalData.userId = r), r) {
            var o = JSON.stringify(e.globalData.cartList);
            wx.request({
                url: e.globalData.urlBase + e.globalData.urlAddServeOrder,
                data: {
                    serverId: e.globalData.serverId,
                    serverTime: e.globalData.yuyueTime,
                    gListStr: o,
                    userId: r
                },
                method: "POST",
                header: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                success: function(e) {
                    var a = JSON.parse(e.data);
                    0 != a.code ? (wx.showToast({
                        title: a.msg,
                        icon: "none",
                        duration: 2e3
                    }), t.getPayData(a.msg)) : wx.navigateTo({
                        url: "../myReservation/myReservation"
                    });
                }
            });
        } else e.goLogin();
    },
    getPayData: function(a) {
        var t = this, r = e.globalData.urlBase + e.globalData.urlPayData;
        wx.request({
            url: r,
            data: {
                orderId: a,
                userId: e.globalData.userId
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(e) {
                var a = JSON.parse(e.data);
                0 != a.code ? wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 500
                }) : a.price > 0 ? t.wxPay(a) : wx.navigateTo({
                    url: "../myReservation/myReservation"
                });
            }
        });
    },
    wxPay: function(e) {
        wx.requestPayment({
            timeStamp: e.timeStamp,
            nonceStr: e.nonceStr,
            package: "prepay_id=" + e.totalId,
            signType: "MD5",
            paySign: e.sign,
            success: function(e) {
                wx.showToast({
                    title: "支付成功",
                    icon: "none",
                    duration: 500
                });
            },
            fail: function(e) {
                wx.showToast({
                    title: "支付失败",
                    icon: "none",
                    duration: 500
                });
            },
            complete: function(e) {
                wx.navigateTo({
                    url: "../myReservation/myReservation"
                });
            }
        });
    },
    onShow: function() {
        this.setData({
            serDetail: e.globalData.serDetail,
            yuyueTime: e.globalData.yuyueTime
        }), console.log(e.globalData.serDetail);
    },
    choseTime: function() {
        wx.navigateTo({
            url: "../cTime/cTime"
        });
    },
    onShareAppMessage: function() {}
});